<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- yuzl -->
<title>房源租赁网</title>
<style rel="stylesheet" type="text/css">
    body{width:100%;height: 100%;background: url({{static_url('image/dd2.jpg')}}) no-repeat;background-size: 100% 186%;}
</style>
<link rel="stylesheet" type="text/css" href="{{static_url('css/login.css')}}">
<script src="{{static_url('js/jquery-3.2.1.js')}}" type="text/javascript"></script>
	<!--10/30peng修改-->
</head>
<body>
	<div id="form-ln">
		<div style="height:30px;"></div>

		<div class="login-wrap">
			<div class="login-html">
					<input id="tab-1" type="radio" name='tab'  class="sign-in" checked /><label for="tab-1" class="tab">登录</label>
					<input id="tab-2" type="radio" name='tab' class="sign-up" /><label for="tab-2" class="tab">注册</label>
				<div class="login-form">

					<div class="sign-in-htm">
						<form action="" method="post">
							<div class="group">
								<label for="user" class="label">用户名</label>
								<input id="user_name" name="user_name" type="text" class="input" />
							</div>
							<div class="group">
								<label for="pass" class="label">密码</label>
								<input id="password" name="password" type="password" class="input" data-type="password" />
							</div>
							<div class="group">
								<input id="check" type="checkbox" class="check" checked />
								<label for="check"><span class="icon"></span> 记住密码</label>
							</div>
							<div class="group">
								<input onclick="submitDeng()" type="button" class="button" value="登录" />
							</div>
							<div class="hr"></div>
							<!--<div class="foot-lnk">
								<a href="#forgot">忘记密码?</a>
							</div>-->
						</form>
					</div>

					<form name="form1" method="post" action="">
					<div class="sign-up-htm">
						<div class="group">
							<label for="user" class="label">用户名</label>
							<input id="userName" name="user_name" type="text" class="input" />
						</div>
						<div class="group">
							<label class="label">密码</label>
							<input id="reg_pass" type="password" class="input" data-type="password" name = 'pwd'/>
						</div>
						<div class="group">
							<label class="label">确认密码</label>
							<input id="userPwd" type="password" class="input" data-type="password" name="pwd1"/>
						</div>
						<div class="group">
							<label class="label">邮箱</label>
							<input id="email" name="email" type="text" class="input" />
						</div>
						<div class="group">
							<input type="button" onclick="submitUser()" class="button" value="注册"   />
						</div>
						<div class="hr"></div>

					</div>
					</form>
				</div>
			</div>
		</div>
	</div>


</body>
<!------------------------------------------->
<!--利用js事件进行判断-->
<script type="text/javascript">
	function submitUser (){
        //定义变量名，获取表单中输入的值
		var name=form1.user_name.value;
		var pwd=form1.pwd.value;
		var pwd1 =form1.pwd1.value;
		var email = form1.email.value;
		var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$")
	if((name=="")||(name==null)){
		alert("请输入用户名");
		form1.user.focus();
		//只有return为true时表单才会提交
		return;
	}else if((pwd=="")||(pwd==null)){
		alert("请输入密码！");
		form1.pwd.focus();
		return;

    }else if ((pwd1=='')||(pwd1 ==null)){
        alert('请确认密码');
        form1.pwd1.focus();
        return
	}else if (pwd1 !=pwd){
		alert('您输入的两次密码不一致，还请仔细填写')
		form1.pwd1.focus()
		return
	}else if ((email=='')||(email ==null)) {
        alert('邮箱不能为空');
        form1.email.focus();
        return
		//-----------------------------------------------以上为修改内容---------------------------------------------------
    }else if (!reg.test(email)){
	    alert('您的邮箱格式不对')
		form1.email.focus();
	}
	else{
		 userName = document.getElementById("userName").value;
         //peng
         userreg_pass = document.getElementById('reg_pass').value;
         //------------------------------
         userPwd = document.getElementById("userPwd").value;
         userEmail = document.getElementById("email").value;


         $(function(){
            $.ajax({
                type:'POST',
                url:'/reg',
                //peng
                data:{'userName':userName, 'reg_pass':userreg_pass,'userPwd':userPwd, 'email':userEmail},
                dataType: "json",
                success:function(data){
                    if (data.result == "exits"){
                        alert('用户名已经存在');
                    }
                    //彭20/25------------------------------------------
                    //--------------------------------------------------
                    else if(data.result == "ok"){
                        alert('注册成功');
                        window.location.href="/index";
                    }
                },
                error:function(jqXHR){
                   alert('注册失败');
                },
            });
         });



	}
		}


</script>
	<!-------------------------------------------------->
<script type="text/javascript">



// <!------------------------------登陆------------------------------------>

	 function submitDeng(){
         userName = document.getElementById("user_name").value;
         userPwd = document.getElementById("password").value;

         $(function(){
            $.ajax({
                type:'POST',
                url:'/login',
                //peng
                data:{'userName':userName,'userPwd':userPwd},
                dataType: "json",
                success:function(data){
                    if (data.result == "fail"){
                        alert('登陆失败，用户名或密码错误');
                    }
                    //彭20/25------------------------------------------
					else{
						msg = data.user+'欢迎您'
						alert(msg);
                        window.location.href="/user";
                    }
                     //--------------------------------------------------
                },
                error:function(jqXHR){
                   alert('登陆失败');
                },
            });
         });
     }
</script>
<!---------------------------------------------------------------------->
</html>